/**
 * 
 */
package com.novatialabs.qttt.gwt.client;

import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Grid;

/**
 * @author nchalko
 * 
 */
public class QuantumBoardWidget extends Composite implements HasMarkHandlers, GameDisplayHandler {

  GameCellWidget[] cells = new GameCellWidget[9];

  public QuantumBoardWidget() {

    Grid grid = new Grid(3, 3);
    for (int i = 0; i < cells.length; i++) {
      cells[i] = new GameCellWidget(i + 1);
      grid.setWidget(i / 3, i % 3, cells[i]);
    }
    initWidget(grid);
    setStylePrimaryName("quantum_board");

  }

  public HandlerRegistration addMarkHandler(MarkHandler handler) {
    for (GameCellWidget gameCell : cells) {
      gameCell.addMarkHandler(handler);
      
    }
    return addHandler(handler, MarkEvent.getType());
  }

  public void display(GameModel game) {
    for (GameCellWidget cell : cells) {
      cell.display(game);
    }
  }

  public void display(GameDisplayEvent gameEvent) {
    display(gameEvent.getGame());

  }

}
